import axios from 'axios'
import config from './request.config'
import commonUtils from './commonUtils'

// 创建axios实例
const service = axios.create(config)

// request拦截器
service.interceptors.request.use(config => {
	// 发出请求前的处理
	// config.headers['loginId'] = store.getters.loginId
	//config.headers['sessionKey'] = store.getters.key // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
	return config
}, error => {
	console.log(error)
	Promise.reject(error)
})
// response 拦截器
service.interceptors.response.use(
  // 如果您想要获取诸如头或状态之类的http信息
  // 请返回response=>response
    response => {
      return Promise.resolve(response.data)
    },
    error => {
      
      if(error.response.status==404){
        error.response.status
      }else if(error.response.status==500){
        error.response.status
      }
      
      return Promise.reject(error)
    }
  )
  const PUBLIC_API="/mgaia"
  export default {
    post(url,data){
      url=PUBLIC_API+url
      return service({
        method: 'post',
        url,
        data: data
      })
    },
    get(url,data){
      url=PUBLIC_API+url
      return service({
        method: 'get',
        url,
        params: data
      })
    },
  }